package com.openbravo.pos.inventory;

import com.openbravo.basic.BasicException;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.JImageEditor;
import com.openbravo.data.gui.JMessageDialog;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.SentenceExec;
import com.openbravo.data.loader.SentenceList;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.data.user.EditorRecord;
import com.openbravo.format.Formats;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.forms.DataLogicSales;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.Document;

public class CategoriesEditor extends JPanel
  implements EditorRecord
{
  private SentenceList m_sentcat;
  private ComboBoxValModel m_CategoryModel;
  private SentenceExec m_sentadd;
  private SentenceExec m_sentdel;
  private Object m_id;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel5;
  private JButton m_jCatalogAdd;
  private JButton m_jCatalogDelete;
  private JComboBox m_jCategory;
  private JImageEditor m_jImage;
  private JTextField m_jName;

  public CategoriesEditor(AppView paramAppView, DirtyManager paramDirtyManager)
  {
    DataLogicSales localDataLogicSales = (DataLogicSales)paramAppView.getBean("com.openbravo.pos.forms.DataLogicSales");
    initComponents();
    this.m_sentcat = localDataLogicSales.getCategoriesList();
    this.m_CategoryModel = new ComboBoxValModel();
    this.m_sentadd = localDataLogicSales.getCatalogCategoryAdd();
    this.m_sentdel = localDataLogicSales.getCatalogCategoryDel();
    this.m_jName.getDocument().addDocumentListener(paramDirtyManager);
    this.m_jCategory.addActionListener(paramDirtyManager);
    this.m_jImage.addPropertyChangeListener("image", paramDirtyManager);
    writeValueEOF();
  }

  public void refresh()
  {
    Object localObject;
    try
    {
      localObject = this.m_sentcat.list();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, AppLocal.getIntString("message.cannotloadlists"), localBasicException);
      localMessageInf.show(this);
      localObject = new ArrayList();
    }
    ((List)localObject).add(0, null);
    this.m_CategoryModel = new ComboBoxValModel((List)localObject);
    this.m_jCategory.setModel(this.m_CategoryModel);
  }

  public void writeValueEOF()
  {
    this.m_id = null;
    this.m_jName.setText(null);
    this.m_CategoryModel.setSelectedKey(null);
    this.m_jImage.setImage(null);
    this.m_jName.setEnabled(false);
    this.m_jCategory.setEnabled(false);
    this.m_jImage.setEnabled(false);
    this.m_jCatalogDelete.setEnabled(false);
    this.m_jCatalogAdd.setEnabled(false);
  }

  public void writeValueInsert()
  {
    this.m_id = UUID.randomUUID().toString();
    this.m_jName.setText(null);
    this.m_CategoryModel.setSelectedKey(null);
    this.m_jImage.setImage(null);
    this.m_jName.setEnabled(true);
    this.m_jCategory.setEnabled(true);
    this.m_jImage.setEnabled(true);
    this.m_jCatalogDelete.setEnabled(false);
    this.m_jCatalogAdd.setEnabled(false);
  }

  public void writeValueDelete(Object paramObject)
  {
    Object[] arrayOfObject = (Object[])(Object[])paramObject;
    this.m_id = arrayOfObject[0];
    this.m_jName.setText(Formats.STRING.formatValue(arrayOfObject[1]));
    this.m_CategoryModel.setSelectedKey(arrayOfObject[2]);
    this.m_jImage.setImage((BufferedImage)arrayOfObject[3]);
    this.m_jName.setEnabled(false);
    this.m_jCategory.setEnabled(false);
    this.m_jImage.setEnabled(false);
    this.m_jCatalogDelete.setEnabled(false);
    this.m_jCatalogAdd.setEnabled(false);
  }

  public void writeValueEdit(Object paramObject)
  {
    Object[] arrayOfObject = (Object[])(Object[])paramObject;
    this.m_id = arrayOfObject[0];
    this.m_jName.setText(Formats.STRING.formatValue(arrayOfObject[1]));
    this.m_CategoryModel.setSelectedKey(arrayOfObject[2]);
    this.m_jImage.setImage((BufferedImage)arrayOfObject[3]);
    this.m_jName.setEnabled(true);
    this.m_jCategory.setEnabled(true);
    this.m_jImage.setEnabled(true);
    this.m_jCatalogDelete.setEnabled(true);
    this.m_jCatalogAdd.setEnabled(true);
  }

  public Object createValue()
    throws BasicException
  {
    Object[] arrayOfObject = new Object[4];
    arrayOfObject[0] = this.m_id;
    arrayOfObject[1] = this.m_jName.getText();
    arrayOfObject[2] = this.m_CategoryModel.getSelectedKey();
    arrayOfObject[3] = this.m_jImage.getImage();
    return arrayOfObject;
  }

  public Component getComponent()
  {
    return this;
  }

  private void initComponents()
  {
    this.jLabel2 = new JLabel();
    this.m_jName = new JTextField();
    this.jLabel3 = new JLabel();
    this.m_jImage = new JImageEditor();
    this.m_jCatalogAdd = new JButton();
    this.m_jCatalogDelete = new JButton();
    this.jLabel5 = new JLabel();
    this.m_jCategory = new JComboBox();
    setLayout(null);
    this.jLabel2.setText(AppLocal.getIntString("Label.Name"));
    add(this.jLabel2);
    this.jLabel2.setBounds(20, 20, 80, 14);
    add(this.m_jName);
    this.m_jName.setBounds(100, 20, 180, 18);
    this.jLabel3.setText(AppLocal.getIntString("label.image"));
    add(this.jLabel3);
    this.jLabel3.setBounds(20, 80, 80, 14);
    add(this.m_jImage);
    this.m_jImage.setBounds(100, 80, 240, 180);
    this.m_jCatalogAdd.setText(AppLocal.getIntString("button.catalogadd"));
    this.m_jCatalogAdd.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        CategoriesEditor.this.m_jCatalogAddActionPerformed(paramActionEvent);
      }
    });
    add(this.m_jCatalogAdd);
    this.m_jCatalogAdd.setBounds(370, 20, 170, 24);
    this.m_jCatalogDelete.setText(AppLocal.getIntString("button.catalogdel"));
    this.m_jCatalogDelete.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        CategoriesEditor.this.m_jCatalogDeleteActionPerformed(paramActionEvent);
      }
    });
    add(this.m_jCatalogDelete);
    this.m_jCatalogDelete.setBounds(370, 50, 170, 24);
    this.jLabel5.setText(AppLocal.getIntString("label.prodcategory"));
    add(this.jLabel5);
    this.jLabel5.setBounds(20, 50, 90, 14);
    add(this.m_jCategory);
    this.m_jCategory.setBounds(100, 50, 180, 20);
  }

  private void m_jCatalogDeleteActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      this.m_sentdel.exec(this.m_id);
    }
    catch (BasicException localBasicException)
    {
      JMessageDialog.showMessage(this, new MessageInf(-33554432, AppLocal.getIntString("message.cannotexecute"), localBasicException));
    }
  }

  private void m_jCatalogAddActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      Object localObject = this.m_id;
      this.m_sentdel.exec(localObject);
      this.m_sentadd.exec(localObject);
    }
    catch (BasicException localBasicException)
    {
      JMessageDialog.showMessage(this, new MessageInf(-33554432, AppLocal.getIntString("message.cannotexecute"), localBasicException));
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.inventory.CategoriesEditor
 * JD-Core Version:    0.6.0
 */